//
//  sexViewController.m
//  IMChat
//
//  Created by Admin on 2021/7/2.
//  Copyright © 2021年 TeamOne. All rights reserved.
//

#import "sexViewController.h"

@interface sexViewController ()

@end

@implementation sexViewController

@synthesize myPickerData;

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSArray *array = [[NSArray alloc] initWithObjects:@"男", @"女", nil];
    self.myPickerData = array;
    
}

// pickerView共有多少列
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}

//pickerView每一列各有多少行
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    
    return self.myPickerData.count;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row  forComponent:(NSInteger)component {
    return [myPickerData objectAtIndex:row];
}

//pickerView每一行的高度

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
    
    return 44;
}

- (IBAction)btnClick:(id)sender {
    [self.navigationController popViewControllerAnimated:true];
    NSInteger row = [self.myPickerView selectedRowInComponent:0];
    NSString *selectdata = [myPickerData objectAtIndex:row];
    NSLog(@"你的性别已修改为：%@",selectdata);
    
    /** 获得全局变量. */
    AppDelegate *myDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    myDelegate.user.userSex = selectdata;
    [self alertTool:@"性别修改成功！"];
    
    [TOAFHttpUtils updateUserById:myDelegate.user];
    
}

// 弹窗工具
- (void)alertTool:(NSString *)message{
    //先创建一个弹窗控制器 然后里面有title和message来提示需要的东西
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:message preferredStyle:UIAlertControllerStyleAlert];
    //添加一个弹窗的action 活动可以是取消 可以是确认
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil];
    [alert addAction:sureAction];
    [self presentViewController:alert animated:NO completion:nil];
}

@end

